package utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class TagCluster {
	
	public TagCluster(String line) {
		String s[] = line.split(" ");
		counter = Double.parseDouble(s[0]);
		tags = new ArrayList<String>(s.length/2);
		tag_count = new HashMap<String,Double>();
		tag_idx = new HashMap<String,Integer>();
		int idx = 0;
		for ( int i = 1 ; i <= s.length/2 ; ++i ) {
			tags.add(s[i*2]);
			tag_count.put(s[i*2],Double.parseDouble(s[i*2-1]));
			tag_idx.put(s[i*2],idx++);
		}
	}
	
	private double counter;
	private ArrayList<String> tags;
	private HashMap<String,Double> tag_count;
	private HashMap<String,Integer> tag_idx;
	
	public int getNumTags() {
		return tags.size();
	}
	
	public double getClusterFreq() {
		return counter;
	}
	
	public double getTagRealtiveFreq(String tag) {
		return tag_count.get(tag);
	}
	
	public double getTagFreq(String tag) {
		return getClusterFreq()*getTagRealtiveFreq(tag);
	}
	
	public boolean contains(String tag) {
		return tag_count.containsKey(tag);
	}
		
	@Override
	public String toString() {
		return tags.get(0);
	}

	public List<String> getTags() {
		return tags;
	}

	public int getIdxFor(String tag) {
		return tag_idx.get(tag);
	}
}
